/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.mybatis.plugins;

import org.apache.ibatis.binding.MapperMethod.ParamMap;

/**
 * @auther ebert_chan
 */
class ContextParamMap extends ParamMap<Object> {

    public static final String DEFAULT_ARG_NAME = "arg0";

    public static final String DEFAULT_CONTEXT_NAME = "context";

    public static final String DEFAULT_PAGE_NAME = "page";

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /*
     * @see org.apache.ibatis.binding.MapperMethod.ParamMap#get(java.lang.Object)
     */
    @Override
    public Object get(Object key) {
        if (!this.containsKey(key)) {

            switch (this.size()) {
                case 2:
                    if (this.containsKey(DEFAULT_ARG_NAME) && (this.containsKey(DEFAULT_PAGE_NAME) || this.containsKey(DEFAULT_CONTEXT_NAME))) {
                        return this.get(DEFAULT_ARG_NAME);
                    }
                    break;
                case 3:
                    if (this.containsKey(DEFAULT_ARG_NAME) && this.containsKey(DEFAULT_PAGE_NAME) && this.containsKey(DEFAULT_CONTEXT_NAME)) {
                        return this.get(DEFAULT_ARG_NAME);
                    }
                    break;
            }

        }
        return super.get(key);
    }

}